<?php
namespace Chat\Controller;
use Think\Controller;

class DebugController extends Controller{

    public function _initialize(){

    }

    public function test()
    {
        $kf_list = M('rbac_manager')->select();
        foreach ($kf_list as $key => $kf) {
            $kefuInfo = M('kf')->where(['openid'=>$kf['openid']])->find();
            if($kefuInfo){
                $customer = M('customer')->where(['phone'=>$kf['phone']])->find();
                if($customer){
                    if($customer['openid']!=$kf['openid']){
                        $data = [
                            'openid'    =>$kf['openid']
                        ];
                        M('customer')->where(['id'=>$customer['id']])->save($data);
                        dump('----------------');
                        dump($data);
                    }
                }else{
                        $data = [
                            'phone' => $kf['phone'], 
                            'openid'=> $kf['openid'],
                            'plot'  => 0, 
                            'name'  => $kefuInfo['kf_nickname'],
                            'sex'   => $kf['sex'], 
                            'ctime' => time(),
                            'mtime' => time(),
                            'pwd'   => $kf['password'],
                        ];
                        M('customer')->add($data);
                        dump('----------------');
                        dump($data);
                }
            }else{
                dump('不存在');
                dump($kf);
            }
        }
        exit('');
    }
}